// Wrapper around argparser; exports relevant args
import './env'; // ensure env loaded
import ArgParser from '@3xpo/argparser';
import { logger } from './logger';

const argParser = new ArgParser();

argParser
  .defineArgument({
    type: 'boolean',
    name: 'development',
    aliases: ['d', 'devel', 'develop'],
    default: process.env.NODE_ENV === 'development',
    description: 'Use development mode',
  })
  .defineArgument({
    type: 'boolean',
    name: 'help',
    aliases: ['h'],
    default: false,
    description: 'Stops it, gets some help',
  })
  .defineArgument({
    type: 'string',
    name: 'token',
    aliases: [],
    default: null,
    description: 'Force overwrites the token',
  })
  .defineArgument({
    type: 'string',
    name: 'db',
    aliases: [],
    default: null,
    description: 'Force overwrites the db connection url',
  });

export const _parseResult = argParser.parse<{
  help: boolean;
  development: boolean;
  token?: string;
}>(argParser.hideBin(process.argv));

if (_parseResult.help) {
  console.log(argParser.help('botbase'));
  process.exit(0);
}
export const isDev = _parseResult.development;

if (!isDev && process.env.NODE_ENV !== 'production')
  logger.warn(
    'Did not call with dev flag, yet NODE_ENV is not production! This is bad!',
  );
